package com.by.facade.enums.information;

import com.by.facade.consts.PromotionPlatformTypeConst;
import com.by.facade.enums.information.sub.BaiDuPromotionPlatformEventEnum;
import com.by.facade.enums.information.sub.GuangDianTongPromotionPlatformEventEnum;
import com.by.facade.enums.information.sub.JuLiangPromotionPlatformEventEnum;
import com.by.facade.enums.information.sub.KuaiShouPromotionPlatformEventEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Tian Wei
 * @version 1.0
 * @date 2024/2/28 10:30 AM
 */
@Getter
@AllArgsConstructor
public enum PromotionPlatformTypeEnum {

    JU_LIANG(PromotionPlatformTypeConst.JU_LIANG, "巨量引擎"),
    GUANG_DIAN_TONG(PromotionPlatformTypeConst.GUANG_DIAN_TONG, "广点通(腾讯广告)"),
    KUAI_SHOU(PromotionPlatformTypeConst.KUAI_SHOU, "快手"),
    BAI_DU(PromotionPlatformTypeConst.BAI_DU, "百度"),

    ;

    private final Integer type;

    private final String desc;

    public static final Map<Integer, Map<Integer, Enum>> PROMOTION_PLATFORM_EVENT_TYPE_MAP = new ConcurrentHashMap<>();

    static {
        PromotionPlatformTypeEnum.PROMOTION_PLATFORM_EVENT_TYPE_MAP.put(PromotionPlatformTypeEnum.BAI_DU.getType(), Stream.of(BaiDuPromotionPlatformEventEnum.values()).collect(Collectors.toMap(BaiDuPromotionPlatformEventEnum::getPromotionPlatformEventType, Function.identity())));
        PromotionPlatformTypeEnum.PROMOTION_PLATFORM_EVENT_TYPE_MAP.put(PromotionPlatformTypeEnum.GUANG_DIAN_TONG.getType(), Stream.of(GuangDianTongPromotionPlatformEventEnum.values()).collect(Collectors.toMap(GuangDianTongPromotionPlatformEventEnum::getPromotionPlatformEventType, Function.identity())));
        PromotionPlatformTypeEnum.PROMOTION_PLATFORM_EVENT_TYPE_MAP.put(PromotionPlatformTypeEnum.JU_LIANG.getType(), Stream.of(JuLiangPromotionPlatformEventEnum.values()).collect(Collectors.toMap(JuLiangPromotionPlatformEventEnum::getPromotionPlatformEventType, Function.identity())));
        PromotionPlatformTypeEnum.PROMOTION_PLATFORM_EVENT_TYPE_MAP.put(PromotionPlatformTypeEnum.KUAI_SHOU.getType(), Stream.of(KuaiShouPromotionPlatformEventEnum.values()).collect(Collectors.toMap(KuaiShouPromotionPlatformEventEnum::getPromotionPlatformEventType, Function.identity())));
    }

    public static Integer getPromotionPlatformEventType(Integer promotionPlatformType, Integer userBehaviorType) {

        Integer promotionPlatformEventType = PromotionPlatformEventTypeEnum.resolveByUserBehaviorType(userBehaviorType);
        if (Objects.isNull(promotionPlatformEventType)) {
            return null;
        }
        Boolean containPromotionPlatformEvent = PROMOTION_PLATFORM_EVENT_TYPE_MAP.getOrDefault(promotionPlatformType, Collections.emptyMap()).containsKey(promotionPlatformEventType);
        if (!containPromotionPlatformEvent) {
            return null;
        }
        return promotionPlatformEventType;
    }
}
